package cn.juque.jdfsystem.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.juque.common.base.BaseRequestVO;
import cn.juque.common.base.BaseResponseVO;
import cn.juque.common.base.PageInfo;
import cn.juque.common.constants.MessageEnum;
import cn.juque.jdfsystem.entity.RegisterInfo;
import cn.juque.jdfsystem.service.IRegisterInfoService;
import cn.juque.jdfsystem.vo.registerinfo.RegisterInfoDeleteVO;
import cn.juque.jdfsystem.vo.registerinfo.RegisterInfoListVO;
import cn.juque.jdfsystem.vo.registerinfo.RegisterInfoSearchVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author juque
 * @version 1.0.0
 * <ul>
 *     <li>RegisterInfoController</li>
 * </ul>
 * @date 2023-01-10 19:07:20
 **/
@Slf4j
@Controller
@RequestMapping("/jdf/register")
public class RegisterInfoController extends BaseController {

    @Resource
    private IRegisterInfoService registerInfoService;

    /**
     * 查询
     *
     * @param request BaseRequestVO
     * @return BaseResponseVO
     */
    @PostMapping(value = "/list")
    @ResponseBody
    public BaseResponseVO<List<RegisterInfoListVO>> list(@RequestBody BaseRequestVO<RegisterInfoSearchVO> request) {
        RegisterInfoSearchVO searchVO = super.validatorUtil.checkNotNull(request);
        PageInfo pageInfo = request.getPageInfo();
        super.validatorUtil.checkPageInfo(pageInfo);
        RegisterInfo registerInfo = new RegisterInfo();
        BeanUtil.copyProperties(searchVO, registerInfo);
        List<RegisterInfo> list = this.registerInfoService.listInfoWithPage(pageInfo, registerInfo);
        List<RegisterInfoListVO> voList = BeanUtil.copyToList(list, RegisterInfoListVO.class);
        return new BaseResponseVO<>(MessageEnum.OK, voList, pageInfo);
    }

    /**
     * 删除
     *
     * @param request BaseRequestVO
     * @return BaseResponseVO
     */
    @PostMapping(value = "/delete")
    @ResponseBody
    public BaseResponseVO<Boolean> delete(@RequestBody BaseRequestVO<RegisterInfoDeleteVO> request) {
        super.validatorUtil.fastValidate(request);
        List<String> idList = request.getParam().getIdList();
        this.registerInfoService.deleteInfo(idList);
        return new BaseResponseVO<>(MessageEnum.OK, true);
    }
}
